# stoker_defines: Defined constants for Stoker
#
# Author:   Mike Murphy (mamurph@cs.clemson.edu)
# Revision: 13 November 2008
#
#   Copyright 2007-2008 Clemson University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# This material is based upon work supported under a National Science
# Foundation Graduate Research Fellowship. Any opinions, findings,
# conclusions or recommendations expressed in this publication are those of
# the author(s) and do not necessarily reflect the views of the National
# Science Foundation.

import sys, os.path

# Stoker metadata
STOKER_VERSION = 0.90
STOKER_LICENSE = 'Apache v2'
STOKER_VENDOR = 'Clemson University'
STOKER_AUTHOR = 'Mike Murphy, Michael Fenn, Joshua Canter'

# Config file location tweaking
LOCAL_CONFIG_FILENAME = 'stoker.conf'
USER_CONFIG_PATH = '.stoker/stoker.conf'
SYSTEM_CONFIG_PATH = '/etc/stoker.conf'

# Internal tweaks
HOSTNAME_RESOLUTION_LOCAL = 'primary_ip'
MAC_ADDRESS_LOCAL = 'primary_mac'
LOCALE_DIRECTORY = os.path.join(sys.path[0], 'translations')
#ENCODING = 'iso-8859-1'  # For non-UTF8 terminals
ENCODING="utf8"
BUSY_WAIT_INTERVAL = 0.01

# Command mapping
SHORT_OPTIONS = 'short-options'
LONG_OPTIONS = 'long-options'
ARGUMENTS = 'arguments'
MIN_ARGS = 'min-args'
MAX_ARGS = 'max-args'
CMD_CLASS = 'cmd-class'
RESOLVER_RULE = 'resolver-rule'

# Config file keys
CFG_MACHINE_FILE = 'machine_file'
CFG_USE_LDAP = 'use_ldap'
CFG_USE_MYSQL = 'use_mysql'
CFG_CALLABLE_GROUPS = 'callable_groups'
CFG_MACHINE_DEFS = 'search_machine_definitions'
CFG_RESOLVE_HOSTNAME = 'resolve_hostname'
CFG_MAX_THREADS = 'maximum_concurrent_threads'
CFG_WOL_BCAST_ADDR = 'wol_broadcast_address'
CFG_WOL_BCAST_PORT = 'wol_port'
CFG_WOL_TRIES = 'wol_tries'
CFG_WOL_DELAY = 'wol_delay'

# Defaults
DFLT_USE_LDAP = False
DFLT_USE_MYSQL = False
DFLT_RESOLVE_HOSTNAME = False
DFLT_MAX_THREADS = '16'
DFLT_WOL_BCAST_ADDR = '127.0.0.255'
DFLT_WOL_BCAST_PORT = '9'
DFLT_WOL_TRIES = '1'
DFLT_WOL_DELAY = '0'

# LDAP
CFG_LDAP_URI = 'ldap_uri'
CFG_LDAP_TLS = 'ldap_use_tls'
CFG_LDAP_BIND_DN = 'ldap_bind_dn'
CFG_LDAP_BIND_CRED = 'ldap_bind_pw'
CFG_LDAP_BASE_DN = 'ldap_base_dn'
CFG_LDAP_LIMIT = 'ldap_filter'

# LDAP defaults
DFLT_LDAP_URI = 'ldap://localhost'
DFLT_LDAP_TLS = False
DFLT_LDAP_BIND_DN = ''
DFLT_LDAP_BIND_CRED = ''
DFLT_LDAP_BASE_DN = 'ou=DHCP,ou=Hosts,dc=localhost'
DFLT_LDAP_LIMIT = '(objectClass=ipHost)'

# Command config keys
CFG_SSH = 'ssh_command'
CFG_SCP = 'scp_command'

# Command defaults
DFLT_SSH = 'ssh'
DFLT_SCP = 'scp'

# RFC 2307 mappings
NIS_HOSTNAME_ATTR = 'cn'
NIS_HOSTNAME_INDEX = 0
NIS_IP_ATTR = 'ipHostNumber'
NIS_IP_INDEX = 0
NIS_MAC_ATTR = 'macAddress'
NIS_MAC_INDEX = 0

# Control constants
RESOLVE_TO_DEFAULT = -1
RESOLVE_TO_HOSTNAME = 0
RESOLVE_TO_IP = 1
RESOLVE_TO_MAC = 2

# Extra information fields
HOSTNAME_KEY = 'hostname'
IPV4_KEY = 'ipv4'
MAC_KEY = 'mac'

# Exit codes
EXIT_SUCCESS = 0
EXIT_ERROR_CONFIG = 1
EXIT_ERROR_SYNTAX = 2
EXIT_ERROR_LDAP = 3
EXIT_ERROR_TARGET = 4
EXIT_ERROR_MYSQL = 5

# MySQL query strings
CFG_MYSQL_HOST = 'mysql_host'
CFG_MYSQL_DB = 'mysql_db'
CFG_MYSQL_USER = 'mysql_user'
CFG_MYSQL_CRED = 'mysql_cred'
CFG_MYSQL_QUERY_MACHINES = 'mysql_machine_query'
CFG_MYSQL_QUERY_GROUPS = 'mysql_group_query'
CFG_MYSQL_QUERY_RESOLVE_HOSTS = 'mysql_resolve_hosts_query'
CFG_MYSQL_QUERY_RESOLVE_GROUPS = 'mysql_resolve_groups_query'

# MySQL defaults to ROCKS settings, with root password p12345
DFLT_MYSQL_HOST = '127.0.0.1'
DFLT_MYSQL_DB = 'cluster'
DFLT_MYSQL_USER = 'root'
DFLT_MYSQL_CRED = 'p12345'
DFLT_MYSQL_QUERY_MACHINES = 'SELECT name FROM networks'
DFLT_MYSQL_QUERY_GROUPS = 'SELECT rack,name FROM nodes'
DFLT_MYSQL_QUERY_RESOLVE_HOSTS = \
   'SELECT mac, ip, name FROM networks WHERE name IN ("%targets")'
DFLT_MYSQL_QUERY_RESOLVE_GROUPS = \
   'SELECT mac, ip, name FROM networks WHERE name IN ' + \
   '(SELECT name FROM nodes WHERE rack IN ("%targets"))'
#
